<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring声明式事务管理深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-header {
            background: #2d2d2d;
            padding: 10px 20px;
            font-size: 14px;
            color: #888;
            border-bottom: 1px solid #444;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            color: #667eea;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 20px;
        }
        
        .step-number {
            width: 40px;
            height: 40px;
            background: #667eea;
            color: white;
            border-radius: 50%;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            margin-right: 15px;
        }
        
        pre code {
            display: block;
            padding: 20px;
            overflow-x: auto;
            line-height: 1.6;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 relative">
        <div class="container mx-auto px-6 relative z-10">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    Spring声明式事务管理
                    <span class="block text-3xl md:text-4xl mt-4 font-light opacity-90">深度解析与实战指南</span>
                </h1>
                <p class="text-xl md:text-2xl opacity-90 leading-relaxed">
                    通过AOP和代理机制，优雅地实现事务管理与业务逻辑的完美分离
                </p>
                <div class="mt-10 flex justify-center space-x-6">
                    <div class="text-center">
                        <i class="fas fa-layer-group text-4xl mb-2"></i>
                        <p class="text-sm">AOP架构</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-shield-alt text-4xl mb-2"></i>
                        <p class="text-sm">事务保障</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-code text-4xl mb-2"></i>
                        <p class="text-sm">声明式编程</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="content-card rounded-2xl p-8 md:p-12 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">S</span>pring中的声明式事务管理是<strong class="text-purple-700">通过AOP（面向切面编程）和代理机制实现的。</strong>在声明式事务管理中，开发人员只需要通过配置而不是显式编码来管理事务，使得事务管理逻辑与业务逻辑相分离，提高了代码的可维护性和可读性。
            </p>
        </div>

        <!-- Core Concepts -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 text-center">
                <i class="fas fa-cube text-purple-600 mr-3"></i>核心概念解析
            </h2>
            <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                <div class="content-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-database"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">事务管理器</h3>
                    <p class="text-gray-600 leading-relaxed">
                        Spring框架提供的接口，用于管理数据库事务的开启、提交和回滚等操作。支持JDBC、Hibernate、JTA等多种事务管理器。
                    </p>
                </div>
                
                <div class="content-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-bell"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">事务通知</h3>
                    <p class="text-gray-600 leading-relaxed">
                        AOP中的概念，用于在方法执行前、执行后或抛出异常时执行事务管理相关的操作，定义事务的切入点和行为。
                    </p>
                </div>
                
                <div class="content-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-crosshairs"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">切点</h3>
                    <p class="text-gray-600 leading-relaxed">
                        定义哪些方法需要被事务通知拦截和处理，通过配置切点指定目标方法的执行条件，确定事务管理的触发位置。
                    </p>
                </div>
                
                <div class="content-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-sort-amount-up"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">通知顺序</h3>
                    <p class="text-gray-600 leading-relaxed">
                        定义多个事务通知的执行顺序，包括前置通知、后置通知、异常通知等，确保事务管理逻辑按预期顺序执行。
                    </p>
                </div>
                
                <div class="content-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-project-diagram"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">代理对象</h3>
                    <p class="text-gray-600 leading-relaxed">
                        Spring通过动态代理创建目标对象的代理对象，在代理对象的方法中添加事务管理逻辑，实现透明的事务控制。
                    </p>
                </div>
            </div>
        </div>

        <!-- Architecture Diagram -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 text-center">
                <i class="fas fa-sitemap text-purple-600 mr-3"></i>事务管理架构图
            </h2>
            <div class="mermaid">
                graph TB
                    A[客户端请求] --> B[代理对象]
                    B --> C{事务通知}
                    C --> D[事务管理器]
                    D --> E[开启事务]
                    E --> F[执行业务方法]
                    F --> G{执行结果}
                    G -->|成功| H[提交事务]
                    G -->|异常| I[回滚事务]
                    H --> J[返回结果]
                    I --> J
                    
                    style A fill:#f9f,stroke:#333,stroke-width:2px
                    style B fill:#bbf,stroke:#333,stroke-width:2px
                    style C fill:#fbf,stroke:#333,stroke-width:2px
                    style D fill:#bfb,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- Implementation Steps -->
        <div class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 text-center">
                <i class="fas fa-code text-purple-600 mr-3"></i>实战实现步骤
            </h2>
            
            <!-- Step 1 -->
            <div class="content-card rounded-xl p-8 mb-6">
                <h3 class="text-2xl font-bold text-gray-800 mb-4 flex items-center">
                    <span class="step-number">1</span>
                    创建 Spring Boot 项目
                </h3>
                <p class="text-gray-600 mb-4">首先，确保你的项目中已经添加了 Spring Boot 和相关的依赖。使用 Maven 管理依赖：</p>
                <div class="code-block">
                    <div class="code-header">pom.xml</div>
                    <pre><code>&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;com.h2database&lt;/groupId&gt;
        &lt;artifactId&gt;h2&lt;/artifactId&gt;
        &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;</code></pre>
                </div>
            </div>

            <!-- Step 2 -->
            <div class="content-card rounded-xl p-8 mb-6">
                <h3 class="text-2xl font-bold text-gray-800 mb-4 flex items-center">
                    <span class="step-number">2</span>
                    配置数据源和事务管理
                </h3>
                <p class="text-gray-600 mb-4">在 application.properties 文件中配置数据库连接和 JPA 属性：</p>
                <div class="code-block">
                    <div class="code-header">application.properties</div>
                    <pre><code># Database configuration
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=root
spring.datasource.password=root

# JPA configuration
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update</code></pre>
                </div>
            </div>

            <!-- Step 3